package com.derbysoft.lowcostadapter.web.action.model;

import com.derbysoft.lowcostadapter.commons.exception.InputErrorException;
import com.derbysoft.lowcostadapter.commons.model.RateCache;
import com.derbysoft.lowcostadapter.commons.redis.utils.KeyValueHelper;
import org.apache.commons.lang.StringUtils;

/**
 * Created by: jason
 * Date: 2012-09-26
 */
public class RateCondition {
    private String propertyId;
    private String start;
    private String adult;
    private String child;
    private String ratePlanId;
    private String roomTypeId;

    public String getPropertyId() {
        return propertyId;
    }

    public void setPropertyId(String propertyId) {
        this.propertyId = propertyId;
    }

    public String getStart() {
        return start;
    }

    public void setStart(String start) {
        this.start = start;
    }

    public String getAdult() {
        return adult;
    }

    public void setAdult(String adult) {
        this.adult = adult;
    }

    public String getChild() {
        return child;
    }

    public void setChild(String child) {
        this.child = child;
    }

    public String getRatePlanId() {
        return ratePlanId;
    }

    public void setRatePlanId(String ratePlanId) {
        this.ratePlanId = ratePlanId;
    }

    public String getRoomTypeId() {
        return roomTypeId;
    }

    public void setRoomTypeId(String roomTypeId) {
        this.roomTypeId = roomTypeId;
    }

    public String makeKey() {
        return RateCache.PREFIX + KeyValueHelper.SEPARATOR + getPropertyId()
                + KeyValueHelper.SEPARATOR + getStart()
                + KeyValueHelper.SEPARATOR + getAdult()
                + KeyValueHelper.SEPARATOR + getChild();
    }

    public void validate() {
        if (StringUtils.isBlank(propertyId)
                || StringUtils.isBlank(start)
                || StringUtils.isBlank(adult)
                || StringUtils.isBlank(child)) {
            throw new InputErrorException("Required fields can not be empty !");
        }
    }
}
